﻿using System;

using Excel = Microsoft.Office.Interop.Excel;
using Word = Microsoft.Office.Interop.Word;
using System.Windows.Forms;
using Microsoft.VisualBasic;

namespace m_pricelist.Proposal_Services
{
    public class SLAProposal : Proposal
    {
        /*
        #region Member variables
        ProposalService ps;

        int lRow { get; set; }
        int lwtRow { get; set; }
        int lPSRow { get; set; }
        int lHWindex { get; set; }
        int lSWindex { get; set; }
        int lTbIndex { get; set; }
        int cInumber { get; set; }
        int cIname { get; set; }

        string m_sCurrency { get; set; }
        string m_sFinaldest { get; set; }
        string m_sFirstPort { get; set; }
        #endregion

        #region Constructor
        public SLAProposal() 
        {
            lRow = 0;
            lwtRow = 0;
            lPSRow = 0;
            lHWindex = 0;
            lSWindex = 0;
            lTbIndex = 0;
            cInumber = 3;
            cIname = 4;
        }
        #endregion

        #region SLAProposal
        public void GetSLAProposal(object sPath, object sFileToOpen, Word.Application wdApp, Excel.Application xlApp, 
            Excel.Worksheet xlSheet, Excel.Workbook xlWorkBook)
        {
            ps = new ProposalService();

            Word.Document wdDoc = null;
            Word.Table tbl = null;           
            Word.Range PRange = null;    
            try
            {
                m_sFinaldest = txtFinalAdress.Text;
                wdApp = new Word.Application();

                wdApp.ScreenUpdating = false;
                try
                {
                    lPSRow = ps.GetLastUsedCell(3, "Output", xlSheet, xlWorkBook, wdApp);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("There is no data available in the template to work with.", "@\n" + ex);
                }

                if (sFileToOpen == "")
                {
                    wdDoc = wdApp.Documents.Open(sPath);
                }
                else
                {
                    wdDoc = wdApp.Documents.Open(sFileToOpen);
                }

                PRange = wdDoc.Bookmarks.get_Item("CuName").Range;
                PRange.Text = Convert.ToString(xlApp.Sheets["Output"].Range("_AccName").Value);
                wdDoc.Bookmarks.Add("CuName", PRange);

                PRange = wdDoc.Bookmarks.get_Item("Id1").Range;
                PRange.Text = Convert.ToString(xlApp.Sheets["Output"].Range("_OId").Value);
                wdDoc.Bookmarks.Add("Id1", PRange);

                PRange = wdDoc.Bookmarks.get_Item("CuName1").Range;
                PRange.Text = Convert.ToString(xlApp.Sheets["Output"].Range("_AccName").Value);
                wdDoc.Bookmarks.Add("CuName1", PRange);

                #region for each lykkjur út af töflum
                lTbIndex = 1;
                foreach (Word.Table oTable in wdDoc.Tables)
                {
                    //if (oTable.Cell(1, 1).Range.Text.IndexOf("MODEL NUMBER & DESCRIPTION", System.StringComparison.OrdinalIgnoreCase) + 1 != 0)
                    if (Strings.InStr(1, Convert.ToString(oTable.Cell(1, 1).Range.Text), "MODEL NUMBER & DESCRIPTION", CompareMethod.Text) != 0)
                    {
                        lHWindex = lTbIndex;
                        int j = oTable.Rows.Count;
                        for (var l = j; l >= 2; l--)
                        {
                            oTable.Rows[l].Delete();
                        }

                    }
                    //else if (oTable.Cell(1, 1).Range.Text.IndexOf("SOFTWARE MODULE NUMBER AND DESCRIPTION", System.StringComparison.OrdinalIgnoreCase) + 1 != 0)
                    else if ((Strings.InStr(1, Convert.ToString(oTable.Cell(1, 1).Range.Text), "SOFTWARE MODULE NUMBER AND DESCRIPTION", CompareMethod.Text) != 0))
                    {
                        lSWindex = lTbIndex;
                        int j = oTable.Rows.Count;
                        for (var l = j; l >= 2; l--)
                        {
                            oTable.Rows[l].Delete();
                        }
                    }
                    lTbIndex = lTbIndex + 1;
                }
                lwtRow = 2;
                #endregion

                int index = 0;
                tbl = wdDoc.Tables[lHWindex];

                for (lRow = 10; lRow <= lPSRow; lRow++)
                {
                    if (!(xlApp.Sheets["Output"].Rows[lRow].Hidden))
                    {
                        if ((Strings.InStr(1, Convert.ToString(xlApp.Sheets["Output"].Cells(lRow, 1).Value), "a", CompareMethod.Text) != 0)
                            & (Strings.Left(Convert.ToString(xlApp.Sheets["Output"].Cells(lRow, cInumber).Value), 3)) != "inn")
                        {
                            tbl.Rows.Add();
                            tbl.Cell(lwtRow, 1).Range.Text = Convert.ToString(xlApp.Sheets["Output"].Cells(lRow, cInumber).Value + " " + Convert.ToString(xlApp.Sheets["Output"].Cells(lRow, cIname).Value));
                            tbl.Rows[lwtRow].Range.Font.Bold = 0;
                            lwtRow = lwtRow + 1;
                            index++;
                        }
                    }
                }

                lwtRow = 2;
                int index2 = 0;

                tbl = wdDoc.Tables[lSWindex];

                for (lRow = 10; lRow <= lPSRow; lRow++)
                {
                    if (!(xlApp.Sheets["Output"].Rows[lRow].Hidden))
                    {
                        if ((Strings.InStr(1, Convert.ToString(xlApp.Sheets["Output"].Cells(lRow, 1).Value), "a", CompareMethod.Text) != 0)
                            & (Strings.Left(Convert.ToString(xlApp.Sheets["Output"].Cells(lRow, cInumber).Value), 3)) == "inn")
                        {
                            tbl.Rows.Add();
                            tbl.Cell(lwtRow, 1).Range.Text = Convert.ToString(xlApp.Sheets["Output"].Cells(lRow, cInumber).Value + " " + Convert.ToString(xlApp.Sheets["Output"].Cells(lRow, cIname).Value));
                            tbl.Rows[lwtRow].Range.Font.Bold = 0;
                            lwtRow = lwtRow + 1;
                            index2++;
                        }
                    }
                }

                wdApp.ScreenUpdating = true;
                wdApp.Visible = true;

                GC.Collect();
                GC.WaitForPendingFinalizers();

                GC.Collect();
                GC.WaitForPendingFinalizers();

                System.Runtime.InteropServices.Marshal.ReleaseComObject(PRange);

                cmdClose_Click(this, EventArgs.Empty);

            }
            catch (Exception ex)
            {
                ps.CleanUp(string.Empty, wdApp);
                MessageBox.Show("An error came up ", "@/n" + ex);
            }
        }
        #endregion
         * */
    }
}
